﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.Toaster {
    import flash.events.*;
    import flash.display.*;
    import flash.utils.*;
    import __AS3__.vec.*;
    import com.greensock.*;
    import com.greensock.easing.*;

    public class ToasterManager extends Sprite {

        private var m_toasterQueue:Vector.<Toaster>;
        private var m_displayedToaster:Toaster;
        private var m_displayTimeout:uint;
        private var m_isHidingInProgress:Boolean;

        public function ToasterManager(){
            this.m_toasterQueue = new Vector.<Toaster>();
            this.m_isHidingInProgress = false;
        }
        public function show(_arg1:Toaster, _arg2:Boolean=false):void{
            if (((!(this.m_displayedToaster)) || (!(_arg2)))){
                this.m_toasterQueue.push(_arg1);
                this.pump();
            };
        }
        private function pump():void{
            if (((!(this.m_displayedToaster)) && ((this.m_toasterQueue.length > 0)))){
                this.m_displayedToaster = this.m_toasterQueue.shift();
                this.m_displayedToaster.x = (this.m_displayedToaster.y = 0);
                addChild(this.m_displayedToaster);
                TweenLite.to(this.m_displayedToaster, 0.3, {
                    y:-(this.m_displayedToaster.displayHeight),
                    ease:Back.easeOut,
                    onComplete:this.showCompleteHandler
                });
            };
        }
        private function hide():void{
            if (((!(this.m_isHidingInProgress)) && (this.m_displayedToaster))){
                this.m_isHidingInProgress = true;
                this.m_displayedToaster.removeEventListener(Event.CLOSE, this.toasterCloseHandler);
                clearTimeout(this.m_displayTimeout);
                TweenLite.to(this.m_displayedToaster, 0.3, {
                    y:0,
                    ease:Back.easeIn,
                    onComplete:this.hideCompleteHandler
                });
            };
        }
        private function showCompleteHandler():void{
            this.m_displayedToaster.addEventListener(Event.CLOSE, this.toasterCloseHandler);
            this.m_displayTimeout = setTimeout(this.hide, this.m_displayedToaster.duration);
        }
        private function hideCompleteHandler():void{
            this.m_isHidingInProgress = false;
            removeChild(this.m_displayedToaster);
            this.m_displayedToaster = null;
            this.pump();
        }
        private function toasterCloseHandler(_arg1:Event):void{
            this.hide();
        }

    }
}//package Display.Toaster 
